﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="fyysiline_isikType_v3", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(FyysilineIsikTypeV3))]
    public class FyysilineIsikTypeV3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IFyysilineIsikTypeV3 clazz;
        
        public FyysilineIsikTypeV3Serializer(IFyysilineIsikTypeV3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("perenimi");
            if (clazz.Perenimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Perenimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Perenimi");
            }
            Writer.WriteEndElement();
            if (clazz.Synniaeg!=null) {
                Writer.WriteStartElement("synniaeg");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Synniaeg))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Registrikood!=null) {
                Writer.WriteStartElement("registrikood");
                global::Xtee.Core.SerializationMetadata metaRegistrikood = this.GetMetaData(clazz.Registrikood);
                Writer.WriteTypeAttribute(metaRegistrikood.TypeQualifiedName.Namespace, metaRegistrikood.TypeQualifiedName.Name);
                metaRegistrikood.NewSerializer(clazz.Registrikood).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Aadress!=null) {
                Writer.WriteStartElement("aadress");
                global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData(clazz.Aadress);
                Writer.WriteTypeAttribute(metaAadress.TypeQualifiedName.Namespace, metaAadress.TypeQualifiedName.Name);
                metaAadress.NewSerializer(clazz.Aadress).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Residentsus!=null) {
                Writer.WriteStartElement("residentsus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Residentsus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Email!=null) {
                Writer.WriteStartElement("email");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Email))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="eesnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fyysiline_isikType_v3>eesnimi");
                }
                clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fyysiline_isikType_v3>eesnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="perenimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fyysiline_isikType_v3>perenimi");
                }
                clazz.Perenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("perenimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>fyysiline_isikType_v3>perenimi", Reader.LocalName);
            }
            if (Reader.LocalName=="synniaeg") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fyysiline_isikType_v3>synniaeg");
                }
                clazz.Synniaeg = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("synniaeg")).Value;
            }
            if (Reader.LocalName=="registrikood") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaRegistrikood = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IRegistrikoodType>(Reader, "registrikoodType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Registrikood = metaRegistrikood.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IRegistrikoodType>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("registrikood");
                        metaRegistrikood.NewSerializer(clazz.Registrikood).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="aadress") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaAadress = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>(Reader, "aadressType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Aadress = metaAadress.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("aadress");
                        metaAadress.NewSerializer(clazz.Aadress).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="residentsus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Residentsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("residentsus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="email") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>fyysiline_isikType_v3>email");
                }
                clazz.Email = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("email")).Value;
            }
        }
    }
}
